package org.springframework.web.reactive.reactor;

import org.junit.Test;
import reactor.core.publisher.Flux;

/**
 * 测试 Mono 和 Flux 的用法
 *
 * @author zhaorui
 * @Date 2024/6/15  10:43
 * @description:
 */
public class ReactorDemo {

	@Test
	public static void main(String[] args) {
		// mono 创建方式
		// Mono.empty().subscribe(System.out::println);
		// Mono.just("hello mono").subscribe(System.out::println);

		//Flux 创建方式 0~n 元素排序
		// Flux.just(1,2,3,4,5,6).subscribe(System.out::println);
		// Flux.fromIterable(Arrays.asList("a","b","c","d","e")).subscribe(System.out::println);
		// Flux.fromArray(new String[]{"a1","b1","c1","d1","e1"}).subscribe(System.out::println);
		// Flux.fromStream(Stream.of(1,2,3,4,5,6)).subscribe(System.out::println);
		// Flux.range(1,100).subscribe(System.out::println);

		Flux.generate(() -> 0,(i,sink) -> {
			sink.next("2*" + i + "=" + 2 *i);
			if(i==9) sink.complete();
			return i + 1;
		}).subscribe(System.out::println);

	}

}
